from simpy import Environment

from x_pc.core import DeviceCost, Device, DeviceCache


class CarryBiz(DeviceCost, DeviceCache):
    """
    搬运设备 业务数据
    """
    # 编号
    id: str = None
    # 设备编号
    equ_code: str = None
    # 设备类型
    equ_type: int = None
    # 最大同时搬运数
    max_once_operation_num: int = None
    # 取货时间
    clamp_time: int = None
    # 工作类型 关联wops_work_type
    work_type: int = None
    # 是否启用 1启用 2不启用
    enable: int = None

    def __init__(self, kwargs):
        for key in kwargs:
            if hasattr(self, key):
                setattr(self, key, kwargs[key])

    def cost(self, *args, **kwargs) -> float:
        """
        取货时间
        :param args:
        :param kwargs:
        :return:
        """
        return self.clamp_time if self.clamp_time else 0

    def cache_nums(self) -> int:
        """
        缓存数量
        :return:
        """
        return self.max_once_operation_num

    def __str__(self):
        return f'{self.__class__.__name__} (code={self.equ_code})'

    def __repr__(self):
        return self.__str__()


class Carry(Device, CarryBiz):
    """
    搬运设备
    """

    category: str = 'carry'

    def __init__(self, env: Environment, name: str, kwargs):
        Device.__init__(self, env, name)
        CarryBiz.__init__(self, kwargs)

    def device_code(self):
        return self.equ_code

    def loc(self):
        return self.device_code()

    @staticmethod
    def device_type() -> int:
        pass

    def __str__(self):
        return CarryBiz.__str__(self)
